<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>关闭服务</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <link rel="stylesheet" href="../../../css/mui.min.css">
    <link rel="stylesheet" href="../../../css/global.css">
    <link rel="stylesheet" href="../../../css/style.css">
    <link href="../../../css/task.css" rel="stylesheet"/>
    <style type="text/css">
        #div {
            width: 0px;
            height: 0px;
            background: red;
            position: fixed;
            top: 70%;
            left: 50%;
        }

        /*移除底部或顶部三角,需要在删除此代码*/
        .mui-popover .mui-popover-arrow:after {
            width: 0px;
        }

        .details_con {
            background: #fff;
        }

        input.d_ipt {
            width: 60%;
            background: #fff;
        }

        .mui-btn-block {
            border: 0;
            font-size: 16px;
            color: #a9a9a9;
        }

        .selectDate {
            background: url(../../../images/icon_32.png) no-repeat right center !important;
            background-size: 14px 13px !important;
            color: #8E8E93 !important;
        }
    </style>
</head>

<body>

<div id="div"></div>
<div id="popover" class="mui-popover shadow popover">
    <p id="closeTitle" class="title">确定要关闭服务？</p>
    <div class="btn_box">
        <span class="fl" onclick="closepop()">取消</span>
        <span class="fr red" id="quedingupdate">确定</span>
    </div>
</div>

<header class="mui-bar mui-bar-nav">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <h1 id="title" class="mui-title">关闭服务</h1>
</header>
<div class="mui-content">
    <div class="details_con">
        <div class="clum">
            <span class="name">服务编号</span>
            <span class="txt" id="serviceNo"></span>
        </div>
        <div class="clum">
            <span class="name">提交时间</span>
            <span class="txt" id="createTime"></span>
        </div>
        <div class="clum">
            <span class="name">服务子类型</span>
            <span class="txt" id="serviceType"></span>
        </div>
        <div class="clum_arr">
            <span class="name_arr">客户名称</span>
            <span class="txt_arr" id="customerName"></span>
        </div>
        <div class="clum">
            <span class="name">客户类型</span>
            <span class="txt" id="enginnerType"></span>
        </div>
        <div class="clum">
            <span class="name">期望服务时间</span>
            <span class="txt" id="hopeBusinessHours"></span>
        </div>
        <div class="clum">
            <span class="name">服务角色</span>
            <span class="txt">
						<input class="serviceRole" name="serviceRole" type="radio" value="1" disabled="disabled">现场服务&nbsp;&nbsp;
						<input class="serviceRole" name="serviceRole" type="radio" value="2" disabled="disabled">实习
					</span>
        </div>
        <div class="line"></div>
        <div class="my-content-cell">
            <div class="inline-block" id="khxxxx">
                <em>客户详细信息</em>
                <span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
            </div>
        </div>
        <div class="my-content-cell">
            <div class="inline-block" id="yqxx">
                <em>仪器详细信息</em>
                <span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
            </div>
        </div>
		<div class="my-content-cell">
			<div class="inline-block" id="htxx">
				<em>合同详细信息</em>
				<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
			</div>
		</div>
        <div class="my-content-cell">
            <div class="inline-block" id="fwtzxx">
                <em>服务通知详细信息</em>
                <span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
            </div>
        </div>
        <div class="my-content-cell">
            <div class="inline-block" id="tjsybjxx">
                <em>推荐使用备件详细信息</em>
                <span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
            </div>
        </div>
        <div class="my-content-cell">
            <div class="inline-block" id="xxggsq">
                <em>信息更改申请</em>
                <span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
            </div>
        </div>
        <div class="my-content-cell">
            <div class="inline-block" id="ckbg">
                <em>查看报告</em>
                <span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
            </div>
        </div>
        <div class="my-content-cell">
            <div class="inline-block" id="ckrz">
                <em>查看日志</em>
                <span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
            </div>
        </div>
        <div class="my-content-cell">
            <div class="inline-block" id="report">
                <em>Error Report&Hot Account Report</em>
                <span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
            </div>
        </div>
    </div>
    <div class="btn_box">
        <span id="addAttach" class="fl">添加附件</span>
        <span class="fr red" id="gb">关闭服务</span>
    </div>
    <div style="height: 50px;"></div>
</div>

<!-- js代码 start -->

<!-- 基础js start -->
<script src="../../../js/mui.min.js"></script>
<script src="../../../js/utils/h.js"></script>
<script src="../../../js/constant.js"></script>
<script src="../../../js/common.js"></script>
<script src="../../../js/utils/base64.js"></script>
<script src="../../../js/utils/md5.js"></script>
<script src="../../../js/utils/sortMap.js"></script>
<script src="../../../js/utils/http.js"></script>
<script src="../../../js/app.js"></script>
<!-- 基础js end -->
<script src="../../../js/utils/rolldate.min.js"></script>
<script type="text/javascript" charset="utf-8">
    var ServiceNoticeId
    var serviceNo
    var planId
    var planState

    // 仪器详情用带过去
    var trainQuota
    var installationDate
    var cfda

    // 服务通知详细信息用
    var serviceType
    var isWarranty
    var troubleDescription
    var remark
    var serviceRole
    var longitude
    var latitude
    var planId
    var signInTime

    // report用
    var divBu
    var problem

    (function ($, doc) {
        $.init();

        $.plusReady(function () {

            // 从上一个页面取值
            var self = plus.webview.currentWebview();
            // 获取上一个页面传过来的参数并显示到页面
            ServiceNoticeId = self.ServiceNoticeId;
            serviceNo = self.serviceNo;
            planId = self.planId;

            // console.log("ServiceNoticeId:"+ServiceNoticeId+"	serviceNo:"+serviceNo+"	planId:"+planId)

            // 获取详情的方法
            getDetails();

            // 客户详细信息
            h("#khxxxx").tap(function () {
                app.jumpTo("/view/service/accept/customerDetails.html", "view/service/accept/customerDetails.html",
                    {
                        ServiceNoticeId: ServiceNoticeId,
                        serviceNo: serviceNo,
                        planId: planId
                    });
            })

            // 仪器详细信息
            h("#yqxx").tap(function () {
                app.jumpTo("/view/service/accept/instrumentDetails.html", "view/service/accept/instrumentDetails.html",
                    {
                        ServiceNoticeId: ServiceNoticeId,
                        serviceNo: serviceNo,
                        planId: planId,
                        trainQuota: trainQuota,
                        installationDate: installationDate,
                        cfda: cfda
                    });
            })

            // 服务通知详细信息
            h("#fwtzxx").tap(function () {
                app.jumpTo("/view/service/accept/noticeDetails.html", "view/service/accept/noticeDetails.html",
                    {
                        ServiceNoticeId: ServiceNoticeId,
                        serviceNo: serviceNo,
                        planId: planId,
                        serviceType: serviceType,
                        isWarranty: isWarranty,
                        troubleDescription: troubleDescription,
                        remark: remark
                    });
            })

            // 推荐使用备件详细信息
            h("#tjsybjxx").tap(function () {
                app.jumpTo("/view/service/accept/partDetails.html", "view/service/accept/partDetails.html",
                    {
                        ServiceNoticeId: ServiceNoticeId,
                        serviceNo: serviceNo,
                        planId: planId
                    });
            })

            // 信息更改申请
            h("#xxggsq").tap(function () {
                app.jumpTo("/view/service/accept/infoUpdate.html", "view/service/accept/infoUpdate.html",
                    {
                        ServiceNoticeId: ServiceNoticeId,
                        serviceNo: serviceNo,
                        noticeId: ServiceNoticeId,
                        planId: planId
                    });
            })

            // 查看日志
            h("#ckrz").tap(function () {
                //alert(serviceNo);
                app.jumpTo("/view/service/serviceLog/noticeLogList.html", "view/service/serviceLog/noticeLogList.html",
                    {
                        serviceNo: serviceNo,
                        planId: planId
                    });
            })
            // 查看报告
            h("#ckbg").tap(function () {
                app.jumpTo("/view/service/report/work/workReportList.html", "view/service/report/work/workReportList.html",
                    {
                        serviceNo: serviceNo,
                        planState: planState,
                        noticeId: ServiceNoticeId,
                        planId: planId,
                        phoneRep:1
                    });
            })
			
			// 合同详细信息
			h("#htxx").tap(function(){
				 app.jumpTo("/view/service/accept/contractDetails.html", "view/service/accept/contractDetails.html",{
					serviceNo: serviceNo,
				 });
			})
			
            // Error Report&Hot Account Report
            h("#report").tap(function () {
                app.jumpTo("/view/service/report/errorhot/erroOrHot.html", "view/service/report/errorhot/erroOrHot.html",
                    {
                        serviceNo: serviceNo,
                        serviceType: serviceType,
                        planId: planId,
                        noticeId: ServiceNoticeId,
                        divBu: divBu,
                        problem: problem
                    });
            })


            h("#gb").tap(function () {
                if (serviceType && serviceType == '安装') {
                    // 安装单 验证核对仪器序列号是否一致
                    app.showWaiting('正在提交...')
                    ajaxGet(BASE_URL + "cc/instrument/checkSerialNumberAndCaseByServiceNotice", {
                        "serviceNo": serviceNo
                    }, function (res) {
                        console.debug(res)
                        if (res.code == 200) {
                            if (res.data.ischecked == "1") {
                                // 一致
                                if (res.data.caseIsClosed == "1") {
                                    //无未完成的case
                                    h("#closeTitle").html('确定要关闭服务？')
                                } else {
                                    //有未完成的case
                                    h("#closeTitle").html('您有升级的CASE未处理完成，是否确认关闭服务？')

                                }
                                app.closeWaiting()
                                mui("#popover").popover('toggle', document.getElementById("div"));

                            } else {
                                // 不一致
                                app.closeWaiting()
                                app.toast("请核对序列号信息是否一致")

                            }

                        } else {
                            app.closeWaiting()
                            app.toast(res.msg)
                        }
                    }, function (errorMsg) {
                        app.closeWaiting()
                        app.toast("关闭失败")
                        console.log(JSON.stringify(errorMsg))
                    });
                } else {
                    ajaxGet(BASE_URL + "cc/instrument/checkSerialNumberAndCaseByServiceNotice", {
                            "serviceNo": serviceNo
                        }, function (res) {
                            console.debug(res)
                            if (res.data.caseIsClosed == "1") {
                                //无未完成的case
                                h("#closeTitle").html('确定要关闭服务？')
                            } else {
                                //有未完成的case
                                h("#closeTitle").html('您有升级的CASE未处理完成，是否确认关闭服务？')

                            }
                            mui("#popover").popover('toggle', document.getElementById("div"));
                        },
                        function (errorMsg) {
                            app.closeWaiting()
                            app.toast("关闭失败")
                        }
                    )
                    // 非安装单

                }
            })

            h("#addAttach").tap(function () {
                app.jumpTo("/view/service/notice/signCloseReport.html", "view/service/notice/signCloseReport.html",
                    {
                        serviceNo: serviceNo,
                        planId: planId,
                        planState: planState,
                        noticeId: ServiceNoticeId,
                        serviceType: serviceType,
                        /* orderReceivedDate:orderReceivedDate,
                      isWarranty: isWarranty,
                      subServiceType: subServiceType,
                      problem: problem*/
                    });
            })
            // 确定关闭方法
            h("#quedingupdate").tap(function () {
                guanbi()
            })

        });


        // 获取详情的方法
        function getDetails() {
            app.showWaiting('加载中...')
            ajaxGet(BASE_URL + "cc/notice/getMyServiceNoticeDetail", {
                "ServiceNoticeId": ServiceNoticeId,
                "EnginnerId": app.getUser().enginnerId
            }, function (data) {
                app.closeWaiting()
                console.log(JSON.stringify(data))
                if (data.code == 200) {
                    if (data.data != "") {
                        h("#serviceNo").html(data.data[0].serviceNo);
                        h("#createTime").html(data.data[0].createTime);
                        h("#serviceType").html(data.data[0].subServiceType);
                        planState = data.data[0].planState;
                        problem = data.data[0].troubleDescription;
                        divBu = data.data[0].divBu;
                        h("#customerName").html(data.data[0].customerName);
                        if (data.data[0].enginnerType == undefined || data.data[0].enginnerType == "") {
                            h("#enginnerType").html("无");
                        } else {
                            h("#enginnerType").html(data.data[0].enginnerType);
                        }
                        if (data.data[0].hopeBusinessHours == undefined || data.data[0].hopeBusinessHours == "") {
                            h("#hopeBusinessHours").html("无");
                        } else {
                            h("#hopeBusinessHours").html(data.data[0].hopeBusinessHours);
                        }

                        // 仪器详细信息页面用
                        if (data.data[0].trainQuota == undefined || data.data[0].trainQuota == "") {
                            trainQuota = "";
                        } else {
                            trainQuota = data.data[0].trainQuota;
                        }
                        if (data.data[0].installationDate == undefined || data.data[0].installationDate == "") {
                            installationDate = "";
                        } else {
                            installationDate = data.data[0].installationDate;
                        }
                        if (data.data[0].cfda == undefined || data.data[0].cfda == "") {
                            cfda = "";
                        } else {
                            cfda = data.data[0].cfda;
                        }

                        // 服务通知详细信息页面用
                        if (data.data[0].serviceType == undefined || data.data[0].serviceType == "") {
                            serviceType = "";
                        } else {
                            serviceType = data.data[0].serviceType;
                        }
                        if (data.data[0].isWarranty == undefined || data.data[0].isWarranty == "") {
                            isWarranty = "";
                        } else {
                            isWarranty = data.data[0].isWarranty;
                        }
                        if (data.data[0].troubleDescription == undefined || data.data[0].troubleDescription == "") {
                            troubleDescription = "";
                        } else {
                            troubleDescription = data.data[0].troubleDescription;
                        }
                        if (data.data[0].remark == undefined || data.data[0].remark == "") {
                            remark = "";
                        } else {
                            remark = data.data[0].remark;
                        }

                        serviceRole = data.data[0].serviceRole
                        if (serviceRole) {
                            document.querySelector(`input[name='serviceRole'][value='${serviceRole}']`).checked = true;
                        }

                    }

                } else {
                    app.toast(data.msg)
                }
            }, function (errorMsg) {
                app.closeWaiting()
                console.log(JSON.stringify(errorMsg))
                app.toast(errorMsg)
            });
        }
    }(mui, document));


    // 取消方法 关闭弹窗
    function closepop() {
        mui("#popover").popover('hide', document.getElementById("div"));
    }

    function guanbi() {
        app.showWaiting('正在提交...')
        ajaxGet(BASE_URL + "cc/notice/closeNotice", {
            "serviceNo": serviceNo,
            "enginnerId": app.getUser().enginnerId,
            "ServiceNoticeId": ServiceNoticeId
        }, function (data) {
            app.closeWaiting()
            mui("#popover").popover('toggle', document.getElementById("div"));
            console.log(JSON.stringify(data))
            if (!data.data){
                app.toast(data.msg)
            }
            if (data.data.data.status === '1') {
                app.toast(data.msg)
                var maintenanceReport = plus.webview.getWebviewById('view/service/report/maintenanceReport.html');
                if (maintenanceReport) {
                    maintenanceReport.close()
                }

                var signOutAddReport = plus.webview.getWebviewById('view/service/notice/signOutAddReport.html');
                if (signOutAddReport) {
                    signOutAddReport.close()
                }

                var signInAddReport = plus.webview.getWebviewById('view/service/notice/signInAddReport.html');
                if (signInAddReport) {
                    signInAddReport.close()
                }

                var checkedInList = plus.webview.getWebviewById('view/service/notice/checkedInList.html');
                if (checkedInList) {
                    checkedInList.close()
                }

                // 关闭进行中
                var conductList = plus.webview.getWebviewById('view/service/assign/conductList.html');
                if (conductList) {
                    conductList.close()
                }

                var completedList = plus.webview.getWebviewById('view/service/notice/completedList.html');
                if (completedList) {
                    completedList.close()
                }

                // 1、刷新FSE首页
                var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
                if (indexFSE) {
                    indexFSE.evalJS('getList("1")')
                }

                var self = plus.webview.currentWebview();
                var closedList = plus.webview.getWebviewById('view/service/notice/closedList.html');
                if (closedList) {
                    closedList.evalJS('initData()')
                    mui.back()
                } else {
                    var self = plus.webview.currentWebview();
                    var closedList1 = plus.webview.create('/view/service/notice/closedList.html', 'view/service/notice/closedList.html')
                    closedList1.show()
                    var signIn = plus.webview.getWebviewById('view/service/notice/signIn.html');
                    var acceptedList = plus.webview.getWebviewById('view/service/notice/acceptedList.html');
                    var customerReportList = plus.webview.getWebviewById('view/service/notice/customerReportList.html');
                    var workReportList = plus.webview.getWebviewById('view/service/report/work/workReportList.html');
                    signIn && signIn.close()
                    acceptedList && acceptedList.close()
                    customerReportList && customerReportList.close()
                    workReportList && workReportList.close()
                    self.close()
                }
                // app.jumpTo('/view/service/notice/closedList.html','view/service/notice/closedList.html')
            } else {
                mui("#popover").popover('hide', document.getElementById("div"));
                app.closeWaiting()
                app.toast(data.data.data.message)
            }
        }, function (errorMsg) {
            app.closeWaiting()
            app.toast("关闭失败")
        });
    }
    h('.mui-action-back').tap(function () {
        pageReload()
    })
    //返回刷新列表
    function pageReload() {
        var conductList = plus.webview.getWebviewById('view/service/assign/conductList.html');
        var assignList = plus.webview.getWebviewById('view/service/notice/acceptedList.html');
        var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
        var completedList = plus.webview.getWebviewById('view/service/notice/completedList.html');
        conductList&&conductList.evalJS('getList()')
        assignList&&assignList.evalJS('getList()')
        indexFSE&&indexFSE.evalJS('getList("1")')
        completedList&&completedList.evalJS('getList("0")')
    }
</script>
<!-- js代码 end -->

</body>

</html>
